<template>
  <div class="toast" v-show="isShow">
    <div>{{msg}}</div>
  </div>
</template>

<script>
export default {
  name: "toast",
  //   props: {
  //     msg: {
  //       type: String,
  //       default: "我是Toast！"
  //     },
  //     isShow: {
  //       type: Boolean,
  //       default: false
  //     }
  //   },
  data() {
    return {
      msg: "",
      isShow: false
    };
  },
  methods: {
    show(msg = "我是Toast！", duration = 1500) {
      (this.isShow = true), (this.msg = msg);
      setTimeout(() => {
        this.isShow = false;
        this.msg = "";
      }, duration);
    }
  }
};
</script>

<style scoped>
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 9999;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 3px;
}
</style>